<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
  class ReviewInformationHelper extends AppHelper
  {
    var $helpers = array('CustomFieldDisplay','Rating.Rating');
    function showCustomFields($review)
    {
      $FieldPropertyObject = $this->getAttributes($review);
      $fields = $FieldPropertyObject->getSortedFields();
      $out = "";
      foreach($fields as $field)
      {
        if($FieldPropertyObject->getPropertyValue($field, 'type') == SCHEMA_TYPE_RATING)
        {
          continue;
        }
        $out .= $this->CustomFieldDisplay->showField($FieldPropertyObject,$field,$review['Review']); 
      }
      return $out;
    }

    function getRateableFields($review)
    {
      $FieldPropertyObject = $this->getAttributes($review);
      return $FieldPropertyObject->getFields('type', SCHEMA_TYPE_RATING);
    }
    
    function showDetailedRatings($review)
    {
      $FieldPropertyObject = $this->getAttributes($review);
      $ratableFields = $FieldPropertyObject->getFields('type', SCHEMA_TYPE_RATING);
      $out = "";
      foreach($ratableFields as $field)
      {
        $out .= $FieldPropertyObject->getPropertyValue($field, 'label');
		if (!isset($review['Review'][$field]))
		{
				$review['Review'][$field] = '0.00';
          }
          $out .= $this->Rating->display(array('rating' => $review['Review'][$field], 'tooltip' =>number_format($review['Review'][$field],1)));
      }
      return $out;
    }
    
    function showAverageRating($review,$label = "")
    {
        $FieldPropertyObject = $this->getAttributes($review);
        $out = "";
        //show overall rating if rateable fields are more than one.
        if($review['Review']['avg_score'] && count($FieldPropertyObject->getFields('type', SCHEMA_TYPE_RATING)) > 0)
        {
          $out = $label;
          $out .= $this->Rating->display(array('rating' => $review['Review']['avg_score'], 
                      'tooltip' =>number_format($review['Review']['avg_score'],1),
                      'tooltipClass'=>'overall_'.$review['Review']['id'].'_'.mt_rand(1,1000)));
        }
        return $out;
    }
    /**
     * @return Review
     */
    protected function getReviewModel()
    {
      return cri("Review");
    }
    /**
     * @return ListingFieldProperties
     */
    protected function getAttributes($review)
    {
      return $this->getReviewModel()->getAttributes($review);
    }
  }
?>
